package com.szh.mysobproject.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.szh.mysobproject.http.response.model.WallpaperBean
import com.szh.mysobproject.paging.source.WallpaperPagingSource
import com.szh.mysobproject.viewmodel.app.Repository
import kotlinx.coroutines.flow.Flow

/**
 * @author : create by  szh
 * @date : 2022/7/14 10:30
 * @desc :图片的 viewModel
 */

class PhotoViewModel : ViewModel() {

    /**
     * 获取壁纸列表
     */
    fun getWallpaperList(): Flow<PagingData<WallpaperBean.Res.Vertical>> {
        return Pager(config = PagingConfig(30),
            pagingSourceFactory = { WallpaperPagingSource() }).flow.cachedIn(viewModelScope)
    }

    /**
     * 获取壁纸轮播图
     */
    fun getWallpaperBannerList() = Repository.loadWallpaperBannerList()
}